package com.iotechn.unimall.data.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.iotechn.unimall.data.domain.DistributionDO;
import com.iotechn.unimall.data.dto.DistributionRankingDTO;
import com.iotechn.unimall.data.dto.DistributionUserDTO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: rize
 * Date: 2019/11/27
 * Time: 11:07
 */
public interface DistributionMapper extends BaseMapper<DistributionDO> {

    /**
     * 增加冻结余额
     *
     * @param distributionId
     * @param delta
     * @return
     */
    public Integer incFreezeBalance(@Param("distributionId") Long distributionId, @Param("delta") Integer delta);

    /**
     * 冻结余额 （将余额变为冻结余额）
     *
     * @param distributionId
     * @param delta
     * @return
     */
    public Integer freezeBalance(@Param("distributionId") Long distributionId, @Param("delta") Integer delta);

    /**
     * 将冻结余额变为余额
     *
     * @param distributionId
     * @param delta
     * @return
     */
    public Integer unfreezeBalance(@Param("distributionId") Long distributionId, @Param("delta") Integer delta);

    public Integer decBalance(@Param("distributionId") Long distributionId, @Param("delta") Integer delta);

    /**
     * 将冻结的部分减少 代表已经确认了订单 需要将冻结部分金额减扣掉
     *
     * @param distributionId
     * @param delta
     * @return
     */
    public Integer decFreezeBalance(@Param("distributionId") Long distributionId, @Param("delta") Integer delta);

    public DistributionDO selectByIdForUpdate(Long id);

    public DistributionDO selectByUserIdForUpdate(Long id);

    public Integer selectBalanceByUserId(Long userId);

    public List<DistributionRankingDTO> getDistributionRanking(@Param("offset") Integer offset, @Param("limit") Integer limit);

    public List<DistributionUserDTO> getDistributionUser(@Param("distributionId") Long distributionId);

}
